package com.eight.controller;

import com.eight.pojo.TbCoupon;
import com.eight.sertvice.CouponService;
import com.eight.vo.ComResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO
 * @Author: Van.Planifolia
 * @CreateTime: 2023-02-28  16:06
 * @Version: 1.0
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {

    @Resource(name = "couponService")
    private CouponService couponService;

    /**
     * 获取当前用户可使用的券，条件为指定用户且没过期的券
     * @return 公共的放回结果集合
     */
    @GetMapping("/userEnableCoupon")
    public List<TbCoupon> getUseEnableCoupon(){
        return couponService.getUseEnableCoupon();
    }

    /**
     * 根据优惠券的id查询出一条优惠券记录
     * @param cid 优惠券id
     * @return 查询出现的记录
     */
    @GetMapping("/getCouponByName/{cid}")
    public TbCoupon getCouponByCid(@PathVariable Integer cid){
        return couponService.getById(cid);
    }

}
